<template>
  <div>
    <div style="margin-bottom: 5px;">
      <el-input v-model="name" placeholder="请输入货名" suffix-icon="el-icon-search" style="width: 200px;"
                @keyup.enter.native="loadPost"></el-input>
      <el-select v-model="storage" placeholder="请选择仓库" style="margin-left: 5px;">
        <el-option
            v-for="item in storageData"
            :key="item.id"
            :label="item.name"
            :value="item.id">
        </el-option>
      </el-select>
      <el-select v-model="goodstype" placeholder="请选择分类" style="margin-left: 5px;">
        <el-option
            v-for="item in goodsTypeData"
            :key="item.id"
            :label="item.name"
            :value="item.id">
        </el-option>
      </el-select>
      <el-button type="primary" style="margin-left: 5px;" @click="loadPost">查询</el-button>
      <el-button type="success" @click="resetParam">重置</el-button>
    </div>
    <el-table :data="tableData"
              :header-cell-style="{ background: '#f2f5fc', color: '#555555' }"
              border
    >
      <el-table-column prop="id" label="ID" width="60">
      </el-table-column>
      <el-table-column prop="goodsname" label="货名" width="180">
      </el-table-column>
      <el-table-column prop="storagename" label="仓库" width="180">
      </el-table-column>
      <el-table-column prop="goodstypename" label="分类" width="180">
      </el-table-column>
      <el-table-column prop="adminname" label="操作人" width="180">
      </el-table-column>
      <el-table-column prop="username" label="申请人" width="180">
      </el-table-column>
      <el-table-column prop="count" label="数量" width="180">
      </el-table-column>
      <el-table-column prop="remark" label="备注">
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.page"
        :page-sizes="[5, 10, 20,30]"
        :page-size="this.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.total">
    </el-pagination>

  </div>
</template>

<script>
export default {
  name: "RecordManage",
  data() {
    return {
      goodsTypeData:[],
      storageData:[],
      tableData: [],
      size:5,
      page:1,
      total:0,
      name:'',
      storage:'',
      goodstype:'',
      centerDialogVisible:false,
      form:{
        id:'',
        name:'',
        storage:'',
        goodstype:'',
        count:'',
        remark:''
      },
    }
  },
  methods:{
    formatGoodsType(row){
      let temp =  this.goodsTypeData.find(item=>{
        return item.id == row.goodstype
      })

      return temp && temp.name
    },
    formatStorage(row){
      let temp =  this.storageData.find(item=>{
        return item.id == row.storage
      })

      return temp && temp.name
    },
    // resetForm() {
    //   this.$refs.form.resetFields();
    // },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.size=val
      this.loadPost()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page=val
      this.loadPost()
    },
    resetParam(){
      this.name=''
      this.storage=''
      this.goodstype=''
    },
    loadPost(){
      this.axios.get(this.$httpUrl+'/record/getList',{
        params:{
          page:this.page,
          size:this.size
        }
      }).then(res=>res.data).then(res=>{
        console.log(res)
        let data=res.success;
        if(data){
          this.tableData=res.content.list
          this.total=res.content.total
        }else{
          alert('获取数据失败')
        }
      })
    },
  },
  mounted() {
    this.loadPost()
  }
}
</script>

<style scoped>

</style>